﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;

namespace MyAudioProject
{
    public partial class MainForm : Form
    {
        NAudioRecorder nAudioRecorder = new ();
        public string fileName = @"C:\Users\Administrator\Desktop\hello.wav";

        public MainForm()
        {
            InitializeComponent();
        }

        private void Button_Start_Click(object sender, EventArgs e)
        {
            try
            {
                nAudioRecorder.SetFileName(fileName);
                nAudioRecorder.StartRecorder();
            }
            catch(Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void Button_Stop_Click(object sender, EventArgs e)
        {
            try
            {
                nAudioRecorder.StopRecorder();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void Button_Play_Click(object sender, EventArgs e)
        {
            try
            {
                SoundPlayer soundPlayer = new(fileName);
                soundPlayer.Play();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void TextBox_FileName_TextChanged(object sender, EventArgs e)
        {
            try
            {
                fileName = textBox_FileName.Text.Trim();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
    }
}
